package me.liyiren.backend.controller;

import com.alibaba.fastjson.JSONObject;
import me.liyiren.backend.mqtt.MqttConfig;
import me.liyiren.backend.mqtt.MqttPushClient;
import me.liyiren.backend.vo.RequestData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/")
public class TestController {

    @Autowired
    private MqttPushClient mqttPushClient;

    // 发送自定义消息内容，且指定主题
    @PostMapping("/publishTopic")
    public String test2(@RequestBody RequestData requestData) {
        JSONObject json = new JSONObject(requestData.getData());
        mqttPushClient.publish(1, false, requestData.getTopic(), json.toJSONString());
        return "ok";
    }
}
